let num = 1234
function format(num) {
    if(num.length <= 3) return num
    let str = num + ''
    let arr1 = str.split('.')
    let arr2 = arr1[0].split('')
    let arr3 = []
    for(let i = arr2.length; i > 0; i-=3) {
        arr3.unshift(arr2[i-1])
        arr3.unshift(arr2[i-2])
        arr3.unshift(arr2[i-3])
        arr3.unshift('.')
    }
    arr3.shift()
    
    return arr3.concat(arr1[1] ? ['.',arr1[1]] : '').join('')
}

console.log(format(num));